import { config, dom } from '.'
import { ProjectType } from '../declare';

const excludeTags = ['ui-icon', 'ui-row', 'ui-col', 'ui-row-list'];

export function resolveUsingComponents(templateCode = '') {
    let usingComponents: Record<string, string> = {};
    if (templateCode) {
        let tree = dom.make(templateCode);
        let tags = dom.getTagNamesByRegex(tree, /^(ui(-[\w]+)+)(.*?)/);

        tags.forEach((tag: string) => {
            if (!usingComponents[tag] && excludeTags.indexOf(tag) < 0) {
                usingComponents[tag] = config.projectType === ProjectType.Application ? `touchui-wx-components/${tag}` : tag;
            }
        });
    }
    return usingComponents;
}
